package com.medical.view.admin.user;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormValidatingBehavior;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.Model;
 
import com.medical.model.admin.Account;
import com.medical.model.admin.AdminDbOperation;
import com.medical.model.admin.ListLookUp;
import com.medical.model.admin.Personal;
import com.medical.model.admin.Role;
import com.medical.view.main.MedApp;
import com.medical.view.wicket.Model.MedCompoundModel;
import com.medical.view.wicket.Model.MedModel;
import com.medical.view.wicket.Model.MedPropertyModel;
import com.medical.view.wicket.ajax.html.MedAjaxButton;
import com.medical.view.wicket.ajax.html.MedAjaxEmailField;
import com.medical.view.wicket.ajax.html.MedAjaxForm;
import com.medical.view.wicket.ajax.html.MedAjaxSaveButton;
import com.medical.view.wicket.ajax.html.MedAjaxTelephoneField;
import com.medical.view.wicket.ajax.html.MedAjaxTextArea;
import com.medical.view.wicket.ajax.html.MedAjaxTextField;
import com.medical.view.wicket.ajax.html.MedAjaxYearDateField;
import com.medical.view.wicket.form.MedCheckBox;
import com.medical.view.wicket.form.MedChoiceRenderer;
import com.medical.view.wicket.form.MedDropDownChoice;
import com.medical.view.wicket.form.MedForm;
import com.medical.view.wicket.form.MedPasswordTextField;
import com.medical.view.wicket.form.MedReadButton;
import com.medical.view.wicket.form.MedTelephoneField;
import com.medical.view.wicket.form.MedTextField;
import com.medical.view.wicket.html.modal.MedPop;
import com.medical.view.wicket.html.panal.MedFeedbackPanel;
import com.medical.view.wicket.html.panal.MedPanel;

public class searchUser extends MedPanel {

	public searchUser(String s) {
		super(s);
		add(new searchUserForm("form"));
		add(new UserListTable("UserListTable"));
	}
}

class searchUserForm extends MedForm {

	Personal user = new Personal(new Account());

	public searchUserForm(String id) {
		super(id);

		// account text
		final MedTextField accountTxt = new MedTextField("account.accountName",
				new MedModel());
		add(accountTxt);

		// Role dropDown
		List<Role> roles = AdminDbOperation.listAllRole();
		MedChoiceRenderer<Role> choiceRenderer = new MedChoiceRenderer<Role>(
				"roleName", "id");

		final MedDropDownChoice roleDropDown = new MedDropDownChoice(
				"account.role", new MedModel(), roles, choiceRenderer);
		add(roleDropDown);

		// name text
		final MedTextField nameTxt = new MedTextField("name", new MedModel());
		add(nameTxt);

		// tele text
		final MedTelephoneField teleTxt = new MedTelephoneField("tele",
				new MedModel());
		add(teleTxt);

		MedReadButton addBut = new MedReadButton("search") {
			@Override
			public void onSubmit() {
try{
				System.out.println(teleTxt.getModelObject());
				System.out.println(nameTxt.getModelObject());
				System.out.println(roleDropDown.getModelObject());
				System.out.println(accountTxt.getModelObject());
				Map map=new HashMap ();
				map.put("account.role.id", ((Role)roleDropDown.getModelObject()).getId());
//				map.put("tele", teleTxt.getModelObject());
				AdminDbOperation.listPerson(map);
}catch(Exception e){
	e.printStackTrace();
}
			}
		};

		add(addBut);


	}

}